
#include "EquationSolver.hpp"

const double pi=acos(-1);

// implement the funciton of derived class function1.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function1:public Function{
public:
    double operator()(const double &x) const {
        return (5*pi-10*asin(x)-10*x*pow(1-x*x,0.5)-12.4);
    }
    void sol1()
    {
        Bisection solver1((*this),0.0,1.0,_eps,1000);
        std::cout<<"(I) Bisection method : ";
        solver1.solve();
        std::cout<<std::endl;
    }
}f1;

// implement the funciton of derived class function2.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function2:public Function{
public:
    double operator()(const double &x) const {
        return (5*pi-10*asin(x)-10*x*pow(1-x*x,0.5)-12.4);
    }
    void sol2()
    {
        Newton solver2((*this),0.0,1000);
        std::cout<<"(II) Newton method, x0=0 :  ";
        solver2.solve();
        std::cout<<std::endl;
    }
}f2;

// implement the funciton of derived class function3.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function3:public Function{
public:
    double operator()(const double &x) const {
        return (5*pi-10*asin(x)-10*x*pow(1-x*x,0.5)-12.4);
    }
    void sol3()
    {
        Secant solver3((*this),0.3,0.7,_eps,1000);
        std::cout<<"(III) Secant method, x0=0.3, x1=0.7 :  ";
        solver3.solve();
        std::cout<<std::endl;
    }
}f3;

int main()
{
    std::cout<<"The Assignment E tests three methods on 5pi-10arcsinx-10x(1-x^2)^0.5-12.4=0."<<std::endl<<"The unit is omitted here for convenience of writing."<<std::endl<<std::endl;
    f1.sol1();
    f2.sol2();
    f3.sol3();
    std::cout<<"--------------------Test succeeds.--------------------"<<std::endl<<std::endl;
    return 0;
}

